# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>
pkgname=py3-tornado5
_pkgname=tornado
pkgver=5.1.1
pkgrel=0
pkgdesc="Python3 web framework and asynchronous networking library"
options="!check" # 3 Tests fail by failure to resolve 'localhost'
url="http://www.tornadoweb.org/"
arch="all"
license="Apache-2.0"
depends="python3"
makedepends="python3-dev py3-setuptools"
checkdepends="py3-curl py3-mock py3-twisted"
source="https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz
	rename-to-tornado5.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

replaces="py-tornado" # Backwards compatibility
provides="py-tornado=$pkgver-r$pkgrel" # Backwards compatibility

export TORNADO_EXTENSION=1

prepare() {
	default_prepare

	mv tornado tornado5

	find tornado5 -type f -a \( -name '*.py' -o -name '*.cfg' \)  -exec \
		sed -i -E \
		-e 's/^(\s*(from|import)) tornado/\1 tornado5/' \
		-e 's/tornado\.([a-zA-Z])/tornado5.\1/g' {} \;
}

build() {
	python3 setup.py build
}

check() {
	export PYTHONPATH="$(echo $PWD/build/lib.*)"
	cd build
	python3 -m tornado.test.runtests
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir" --optimize=1
	rm -rf "$subpkgdir"/usr/lib/python3*/site-packages/${_pkgname}5/test
}

sha512sums="f9ecedb20c055981f482c9a2a8bb30082dcc479674f75f6c8654afcf40f2ce5a45e82c7e2b5a6ce5d1c9da7896e865e78c7d29a64b6b1d28d6e74a718be62dc7  tornado-5.1.1.tar.gz
222fcb0c59737f01c7ac16d0b15d104c4ed38048d718166139a4cece707e5f7e65331cc12383cb638e578d2eb6e713a74d6be650c66306c7dc0446b192d13491  rename-to-tornado5.patch"
